package com.ftg.shopping.person.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ftg.shopping.config.LayuiPage;
import com.ftg.shopping.person.entity.sp_personinfo;
import com.ftg.shopping.person.mapper.personMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


@Service
public class personService {
    @Autowired
    personMapper personMapper;

//    public List<sp_personinfo> showAll(){
//        return personMapper.selectList(null);
//    }
//
//    public sp_personinfo findOne(int personid){
//        return personMapper.selectById(personid);
//    }

    public int insertPerson(sp_personinfo  sp){
        return personMapper.insert(sp);
    }

    public int updatePerson(sp_personinfo sp){
        return personMapper.updateperson(sp);
    }

    public int deletePerson(int personid){
        return personMapper.deleteperson(personid);
    }

//    public int deletePersons(List<Integer> ids){
//        return personMapper.deleteBatchIds(ids);
//    }


    public LayuiPage showperson(int page,int limit,String personname){
        LayuiPage layuiPage=new LayuiPage();
        int end = Integer.valueOf(limit);
        int start = (Integer.valueOf(page) - 1) * end;

        if(null != personname && !"".equals(personname)){
            layuiPage.setData(personMapper.findone(start,end,personname));
            layuiPage.setCount(personMapper.findone(start,end,personname).size());
        }else{
            layuiPage.setData(personMapper.showperson(start,end));
            layuiPage.setCount(personMapper.showperson2().size());
        }

        return layuiPage;

    }



}
